#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <cstring>
#include <unistd.h>
#include <assert.h>
#define PATHNAME "./"
#define PROJ_ID 0x3f
#define MSGSZ 128
const mode_t mode = 0666;

key_t getKey()
{
    /**
     * :return 返回key值
     * @return
     */
    key_t ret = ftok(PATHNAME,PROJ_ID);
    assert(ret!=-1);
    return ret;
}

int creatMsg()
{
    /**:function 创建消息队列
     * :return 返回msgid
     * @return
     */
    int msgid = msgget(getKey(),IPC_CREAT|IPC_EXCL|mode);
    assert(msgid!=-1);
    return msgid;
}

int getMsg()
{
    /**:function 获取消息队列
     * :return 返回msgid
     * @return
     */
    int msgid = msgget(getKey(),IPC_CREAT);
    assert(msgid!=-1);
    return msgid;
}
